package model

import (
	"database/sql"
	"time"

	"github.com/guregu/null"
	"github.com/satori/go.uuid"
)

var (
	_ = time.Second
	_ = sql.LevelDefault
	_ = null.Bool{}
	_ = uuid.UUID{}
)

/*
DB Table Details
-------------------------------------


CREATE TABLE "albums"
(
    [AlbumId] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    [Title] NVARCHAR(160)  NOT NULL,
    [ArtistId] INTEGER  NOT NULL,
    FOREIGN KEY ([ArtistId]) REFERENCES "artists" ([ArtistId])
		ON DELETE NO ACTION ON UPDATE NO ACTION
)

JSON Sample
-------------------------------------
{    "album_id": 68,    "title": "pgXVNDioteEoQFRcDwOqnqOML",    "artist_id": 90}



*/

// Albums struct is a row record of the albums table in the main database
type Albums struct {
	//[ 0] AlbumId                                        integer              null: false  primary: true   isArray: false  auto: true   col: integer         len: -1      default: []
	AlbumID int32 `gorm:"primary_key;AUTO_INCREMENT;column:AlbumId;type:integer;" json:"album_id"`
	//[ 1] Title                                          nvarchar(160)        null: false  primary: false  isArray: false  auto: false  col: nvarchar        len: 160     default: []
	Title string `gorm:"column:Title;type:nvarchar;size:160;" json:"title"`
	//[ 2] ArtistId                                       integer              null: false  primary: false  isArray: false  auto: false  col: integer         len: -1      default: []
	ArtistID int32 `gorm:"column:ArtistId;type:integer;" json:"artist_id"`
}

var albumsTableInfo = &TableInfo{
	Name: "albums",
	Columns: []*ColumnInfo{

		{
			Index:              0,
			Name:               "AlbumId",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "integer",
			DatabaseTypePretty: "integer",
			IsPrimaryKey:       true,
			IsAutoIncrement:    true,
			IsArray:            false,
			ColumnType:         "integer",
			ColumnLength:       -1,
			GoFieldName:        "AlbumID",
			GoFieldType:        "int32",
			JSONFieldName:      "album_id",
			ProtobufFieldName:  "album_id",
			ProtobufType:       "int32",
			ProtobufPos:        1,
		},

		{
			Index:              1,
			Name:               "Title",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(160)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       160,
			GoFieldName:        "Title",
			GoFieldType:        "string",
			JSONFieldName:      "title",
			ProtobufFieldName:  "title",
			ProtobufType:       "string",
			ProtobufPos:        2,
		},

		{
			Index:              2,
			Name:               "ArtistId",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "integer",
			DatabaseTypePretty: "integer",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "integer",
			ColumnLength:       -1,
			GoFieldName:        "ArtistID",
			GoFieldType:        "int32",
			JSONFieldName:      "artist_id",
			ProtobufFieldName:  "artist_id",
			ProtobufType:       "int32",
			ProtobufPos:        3,
		},
	},
}

// TableName sets the insert table name for this struct type
func (a *Albums) TableName() string {
	return "albums"
}

// BeforeSave invoked before saving, return an error if field is not populated.
func (a *Albums) BeforeSave() error {
	return nil
}

// Prepare invoked before saving, can be used to populate fields etc.
func (a *Albums) Prepare() {
}

// Validate invoked before performing action, return an error if field is not populated.
func (a *Albums) Validate(action Action) error {
	return nil
}

// TableInfo return table meta data
func (a *Albums) TableInfo() *TableInfo {
	return albumsTableInfo
}
